package com.liliudong.template.generator.controller;

import com.liliudong.template.generator.common.R;
import com.liliudong.template.generator.entity.Table;
import com.liliudong.template.generator.service.GeneratorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代码生成器
 *
 * @author ldli5
 * @classname TableController
 * @date 2024/7/1-14:31
 */
@Slf4j
@RestController
@RequestMapping("/generator")
@RequiredArgsConstructor
public class GeneratorController {

	private final GeneratorService generatorService;

	/**
	 * 全部表
	 *
	 * @return {@link R }<{@link List }<{@link Table }>>
	 */
	@GetMapping("/table/page/{page}/{size}")
	public R<List<Table>> page(@PathVariable Long page, @PathVariable Long size, String tableName) {
		List<Table> tableList = generatorService.page(page, size, tableName);
		return R.ok(tableList);
	}

	/**
	 * 按表名生成
	 *
	 * @param tables 表名称集合
	 */
	@GetMapping("/generate")
	public void generateByTables(HttpServletResponse response,
	                             @RequestParam List<String> tables) {
		generatorService.generateByTables(response, tables);
	}
}
